﻿using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using 基于WPF的电缆采样数据分析系统.Models;
using 基于WPF的电缆采样数据分析系统.Models.CommonUse;
using 基于WPF的电缆采样数据分析系统.Models.Enums;
using 基于WPF的电缆采样数据分析系统.Models.FileLogs;
using 基于WPF的电缆采样数据分析系统.MsgEvents;
using 基于WPF的电缆采样数据分析系统.MsgEvents.AccountingReport;
using 基于WPF的电缆采样数据分析系统.MsgEvents.DeviceStatus;
using 基于WPF的电缆采样数据分析系统.Service;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;

namespace 基于WPF的电缆采样数据分析系统.ViewModels
{
    public class AccountingReportUCViewModel :BindableBase
    {

        /// <summary>
        /// 发布订阅
        /// </summary>
        private readonly IEventAggregator Aggregator;


        /// <summary>
        /// 对话服务
        /// </summary>
        private readonly DialogHostService DialogHostService;


        /// <summary>
        /// 构造器
        /// </summary>
        public AccountingReportUCViewModel()
        {
            Aggregator = App.GetService<IEventAggregator>();

            DialogHostService = App.GetService<DialogHostService>();

            // 更新初始通道
            Aggregator.GetEvent<MsgUpdateInitialChannel>().Subscribe(UpdateInitialChannel);
            // 更新参考波形
            Aggregator.GetEvent<MsgUpdateReferenceWaveform>().Subscribe(UpdateReferenceWaveformInfo);
            // 更新使用文件记录
            Aggregator.GetEvent<MsgUpdateShowUsedFileLogList>().Subscribe(UpdateShowUsedFileLogList);
            // 更新操作日志信息
            Aggregator.GetEvent<MsgUpdateUsedLogList>().Subscribe(UpdateUsedLogList);

            // 更新初始通道信息
            UpdateInitialChannel(GlobalVariableEdit.ChannelStatusList);

            // 更新参考波形信息
            UpdateReferenceWaveformInfo();

            // 更新最近使用的文件信息
            UpdateShowUsedFileLogList();

            // 更新最近使用的文件信息
            UpdateUsedLogList();

            // 选择要显示的列
            SelectTheColumnsToDisplayCmm = new DelegateCommand(SelectTheColumnsToDisplayFun);

            // 使用文件记录根据条件查询
            FileTypeQueryCmm = new DelegateCommand(FileTypeQueryFun);

            // 操作日志根据条件查询
            WorkLogQueryCmm = new DelegateCommand(WorkLogQueryFun);

            // 文件类型选择
            FileTypeSelectionChangedCmm = new DelegateCommand<int?>(FileTypeSelectionChangedFun);
        }


        #region 初始通道

        /// <summary>
        /// 初始通道一状态
        /// </summary>
        private string _InitialChannelOneState = LangugeConvertor.GetValue("NotImported");

        /// <summary>
        /// 初始通道一状态
        /// </summary>
        public string InitialChannelOneState
        {
            get { return _InitialChannelOneState; }
            set { 
                _InitialChannelOneState = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始通道二状态
        /// </summary>
        private string _InitialChannelTwoState = LangugeConvertor.GetValue("NotImported");

        /// <summary>
        /// 初始通道二状态
        /// </summary>
        public string InitialChannelTwoState
        {
            get { return _InitialChannelTwoState; }
            set { 
                _InitialChannelTwoState = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始通道三状态
        /// </summary>
        private string _InitialChannelThreeState = LangugeConvertor.GetValue("NotImported");

        /// <summary>
        /// 初始通道三状态
        /// </summary>
        public string InitialChannelThreeState
        {
            get { return _InitialChannelThreeState; }
            set { 
                _InitialChannelThreeState = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 初始通道一文件路径
        /// </summary>
        private string _InitialChannelOneFilePath = LangugeConvertor.GetValue("Empty");

        /// <summary>
        /// 初始通道一文件路径
        /// </summary>
        public string InitialChannelOneFilePath 
        {
            get { return _InitialChannelOneFilePath; }
            set { 
                _InitialChannelOneFilePath = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始通道二文件路径
        /// </summary>
        private string _InitialChannelTwoFilePath = LangugeConvertor.GetValue("Empty");

        /// <summary>
        /// 初始通道二文件路径
        /// </summary>
        public string InitialChannelTwoFilePath
        {
            get { return _InitialChannelTwoFilePath; }
            set { 
                _InitialChannelTwoFilePath = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 初始通道三文件路径
        /// </summary>
        private string _InitialChannelThreeFilePath = LangugeConvertor.GetValue("Empty");

        /// <summary>
        /// 初始通道三文件路径
        /// </summary>
        public string InitialChannelThreeFilePath
        {
            get { return _InitialChannelThreeFilePath; }
            set { 
                _InitialChannelThreeFilePath = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 更新初始通道信息
        /// </summary>
        private void UpdateInitialChannel(List<ChannelStatus> ChannelStatusList)
        {

            if (ChannelStatusList == null)
            {
                return;
            }

            if (ChannelStatusList[0].IsImportWav == 1)
            {
                InitialChannelOneState = LangugeConvertor.GetValue("HaveBeenImported");
                InitialChannelOneFilePath = ChannelStatusList[0].FilePath;
            }
            else if (ChannelStatusList[0].IsImportWav == 0) {
                InitialChannelOneState = LangugeConvertor.GetValue("NotImported");
                InitialChannelOneFilePath = LangugeConvertor.GetValue("Empty");
            }

            if (ChannelStatusList[1].IsImportWav == 1)
            {
                InitialChannelTwoState = LangugeConvertor.GetValue("HaveBeenImported");
                InitialChannelTwoFilePath = ChannelStatusList[1].FilePath;
            }
            else if (ChannelStatusList[1].IsImportWav == 0)
            {
                InitialChannelTwoState = LangugeConvertor.GetValue("NotImported");
                InitialChannelTwoFilePath = LangugeConvertor.GetValue("Empty");
            }

            if (ChannelStatusList[2].IsImportWav == 1)
            {
                InitialChannelThreeState = LangugeConvertor.GetValue("HaveBeenImported");
                InitialChannelThreeFilePath = ChannelStatusList[2].FilePath;
            }
            else if (ChannelStatusList[2].IsImportWav == 0)
            {
                InitialChannelThreeState = LangugeConvertor.GetValue("NotImported");
                InitialChannelThreeFilePath = LangugeConvertor.GetValue("Empty");
            }
        }


        #endregion


        #region 参考波形

        /// <summary>
        /// 参考波形一是否占用
        /// </summary>
        private string _ReferenceWaveformOneOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形一是否占用
        /// </summary>
        public string ReferenceWaveformOneOccupy
        {
            get { return _ReferenceWaveformOneOccupy; }
            set { 
                _ReferenceWaveformOneOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形二是否占用
        /// </summary>
        private string _ReferenceWaveformTwoOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形二是否占用
        /// </summary>
        public string ReferenceWaveformTwoOccupy
        {
            get { return _ReferenceWaveformTwoOccupy; }
            set { 
                _ReferenceWaveformTwoOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形三是否占用
        /// </summary>
        private string _ReferenceWaveformThreeOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形三是否占用
        /// </summary>
        public string ReferenceWaveformThreeOccupy
        {
            get { return _ReferenceWaveformThreeOccupy; }
            set { 
                _ReferenceWaveformThreeOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形四是否占用
        /// </summary>
        private string _ReferenceWaveformFourOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形四是否占用
        /// </summary>
        public string ReferenceWaveformFourOccupy
        {
            get { return _ReferenceWaveformFourOccupy; }
            set { 
                _ReferenceWaveformFourOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形五是否占用
        /// </summary>
        private string _ReferenceWaveformFiveOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形五是否占用
        /// </summary>
        public string ReferenceWaveformFiveOccupy
        {
            get { return _ReferenceWaveformFiveOccupy; }
            set { 
                _ReferenceWaveformFiveOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形六是否占用
        /// </summary>
        private string _ReferenceWaveformSixOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形六是否占用
        /// </summary>
        public string ReferenceWaveformSixOccupy
        {
            get { return _ReferenceWaveformSixOccupy; }
            set { 
                _ReferenceWaveformSixOccupy = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 参考波形七是否占用
        /// </summary>
        private string _ReferenceWaveformSevenOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形七是否占用
        /// </summary>
        public string ReferenceWaveformSevenOccupy
        {
            get { return _ReferenceWaveformSevenOccupy; }
            set { 
                _ReferenceWaveformSevenOccupy = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形八是否占用
        /// </summary>
        private string _ReferenceWaveformEightOccupy = LangugeConvertor.GetValue("Unoccupied");

        /// <summary>
        /// 参考波形八是否占用
        /// </summary>
        public string ReferenceWaveformEightOccupy
        {
            get { return _ReferenceWaveformEightOccupy; }
            set { 
                _ReferenceWaveformEightOccupy = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 参考波形一是否显示
        /// </summary>
        private string _ReferenceWaveformOneDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形一是否显示
        /// </summary>
        public string ReferenceWaveformOneDisplay
        {
            get { return _ReferenceWaveformOneDisplay; }
            set { 
                _ReferenceWaveformOneDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形二是否显示
        /// </summary>
        private string _ReferenceWaveformTwoDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形二是否显示
        /// </summary>
        public string ReferenceWaveformTwoDisplay
        {
            get { return _ReferenceWaveformTwoDisplay; }
            set { 
                _ReferenceWaveformTwoDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形三是否显示
        /// </summary>
        private string _ReferenceWaveformThreeDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形三是否显示
        /// </summary>
        public string ReferenceWaveformThreeDisplay
        {
            get { return _ReferenceWaveformThreeDisplay; }
            set { 
                _ReferenceWaveformThreeDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形四是否显示
        /// </summary>
        private string _ReferenceWaveformFourDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形四是否显示
        /// </summary>
        public string ReferenceWaveformFourDisplay
        {
            get { return _ReferenceWaveformFourDisplay; }
            set { 
                _ReferenceWaveformFourDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形五是否显示
        /// </summary>
        private string _ReferenceWaveformFiveDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形五是否显示
        /// </summary>
        public string ReferenceWaveformFiveDisplay
        {
            get { return _ReferenceWaveformFiveDisplay; }
            set { 
                _ReferenceWaveformFiveDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形六是否显示
        /// </summary>
        private string _ReferenceWaveformSixDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形六是否显示
        /// </summary>
        public string ReferenceWaveformSixDisplay
        {
            get { return _ReferenceWaveformSixDisplay; }
            set { 
                _ReferenceWaveformSixDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形七是否显示
        /// </summary>
        private string _ReferenceWaveformSevenDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形七是否显示
        /// </summary>
        public string ReferenceWaveformSevenDisplay
        {
            get { return _ReferenceWaveformSevenDisplay; }
            set { 
                _ReferenceWaveformSevenDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形八是否显示
        /// </summary>
        private string _ReferenceWaveformEightDisplay = LangugeConvertor.GetValue("NotShown");

        /// <summary>
        /// 参考波形八是否显示
        /// </summary>
        public string ReferenceWaveformEightDisplay
        {
            get { return _ReferenceWaveformEightDisplay; }
            set { 
                _ReferenceWaveformEightDisplay = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形一命名标签
        /// </summary>
        private string _ReferenceWaveformOneName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形一命名标签
        /// </summary>
        public string ReferenceWaveformOneName
        {
            get { return _ReferenceWaveformOneName; }
            set { 
                _ReferenceWaveformOneName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形二命名标签
        /// </summary>
        private string _ReferenceWaveformTwoName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形二命名标签
        /// </summary>
        public string ReferenceWaveformTwoName
        {
            get { return _ReferenceWaveformTwoName; }
            set { 
                _ReferenceWaveformTwoName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形三命名标签
        /// </summary>
        private string _ReferenceWaveformThreeName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形三命名标签
        /// </summary>
        public string ReferenceWaveformThreeName
        {
            get { return _ReferenceWaveformThreeName; }
            set { 
                _ReferenceWaveformThreeName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形四命名标签
        /// </summary>
        private string _ReferenceWaveformFourName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形四命名标签
        /// </summary>
        public string ReferenceWaveformFourName
        {
            get { return _ReferenceWaveformFourName; }
            set { 
                _ReferenceWaveformFourName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形五命名标签
        /// </summary>
        private string _ReferenceWaveformFiveName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形五命名标签
        /// </summary>
        public string ReferenceWaveformFiveName
        {
            get { return _ReferenceWaveformFiveName; }
            set { 
                _ReferenceWaveformFiveName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形六命名标签
        /// </summary>
        private string _ReferenceWaveformSixName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形六命名标签
        /// </summary>
        public string ReferenceWaveformSixName
        {
            get { return _ReferenceWaveformSixName; }
            set { 
                _ReferenceWaveformSixName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形七命名标签
        /// </summary>
        private string _ReferenceWaveformSevenName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形七命名标签
        /// </summary>
        public string ReferenceWaveformSevenName
        {
            get { return _ReferenceWaveformSevenName; }
            set { 
                _ReferenceWaveformSevenName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 参考波形八命名标签
        /// </summary>
        private string _ReferenceWaveformEightName = LangugeConvertor.GetValue("Nothing");

        /// <summary>
        /// 参考波形八命名标签
        /// </summary>
        public string ReferenceWaveformEightName
        {
            get { return _ReferenceWaveformEightName; }
            set { 
                _ReferenceWaveformEightName = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 更新参考波形信息
        /// </summary>
        private void UpdateReferenceWaveformInfo()
        {
            // 占用
            UpdateReferenceWaveformOccupy();


            // 显示
            UpdateReferenceWaveformDisplay();

            // 命名标签
            UpdateReferenceWaveformName();
        }


        /// <summary>
        /// 更新参考波形占用信息
        /// </summary>
        private void UpdateReferenceWaveformOccupy()
        {
            if (GlobalVariableEdit.R1WavList != null)
            {
                ReferenceWaveformOneOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R1WavList == null)
            {
                ReferenceWaveformOneOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R2WavList != null)
            {
                ReferenceWaveformTwoOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R2WavList == null)
            {
                ReferenceWaveformTwoOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R3WavList != null)
            {
                ReferenceWaveformThreeOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R3WavList == null)
            {
                ReferenceWaveformThreeOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R4WavList != null)
            {
                ReferenceWaveformFourOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R4WavList == null)
            {
                ReferenceWaveformFourOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R5WavList != null)
            {
                ReferenceWaveformFiveOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R5WavList == null)
            {
                ReferenceWaveformFiveOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R6WavList != null)
            {
                ReferenceWaveformSixOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R6WavList == null)
            {
                ReferenceWaveformSixOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R7WavList != null)
            {
                ReferenceWaveformSevenOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R7WavList == null)
            {
                ReferenceWaveformSevenOccupy = LangugeConvertor.GetValue("Unoccupied");
            }

            if (GlobalVariableEdit.R8WavList != null)
            {
                ReferenceWaveformEightOccupy = LangugeConvertor.GetValue("Occupied");
            }
            else if (GlobalVariableEdit.R8WavList == null)
            {
                ReferenceWaveformEightOccupy = LangugeConvertor.GetValue("Unoccupied");
            }
        }


        /// <summary>
        /// 更新参考波形显示信息
        /// </summary>
        private void UpdateReferenceWaveformDisplay()
        {
            if (GlobalVariableEdit.R1Display)
            {
                ReferenceWaveformOneDisplay = LangugeConvertor.GetValue("Displayed"); 
            } else
            {
                ReferenceWaveformOneDisplay = LangugeConvertor.GetValue("NotShown");
            }


            if (GlobalVariableEdit.R2Display)
            {
                ReferenceWaveformTwoDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformTwoDisplay = LangugeConvertor.GetValue("NotShown");
            }

            if (GlobalVariableEdit.R3Display)
            {
                ReferenceWaveformThreeDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformThreeDisplay = LangugeConvertor.GetValue("NotShown");
            }

            if (GlobalVariableEdit.R4Display)
            {
                ReferenceWaveformFourDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformFourDisplay = LangugeConvertor.GetValue("NotShown");
            }


            if (GlobalVariableEdit.R5Display)
            {
                ReferenceWaveformFiveDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformFiveDisplay = LangugeConvertor.GetValue("NotShown");
            }


            if (GlobalVariableEdit.R6Display)
            {
                ReferenceWaveformSixDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformSixDisplay = LangugeConvertor.GetValue("NotShown");
            }

            if (GlobalVariableEdit.R7Display)
            {
                ReferenceWaveformSevenDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformSevenDisplay = LangugeConvertor.GetValue("NotShown");
            }

            if (GlobalVariableEdit.R8Display)
            {
                ReferenceWaveformEightDisplay = LangugeConvertor.GetValue("Displayed");
            }
            else
            {
                ReferenceWaveformEightDisplay = LangugeConvertor.GetValue("NotShown");
            }
        }



        /// <summary>
        /// 更新参考波形命名信息
        /// </summary>
        private void UpdateReferenceWaveformName()
        {
            ReferenceWaveformOneName = GlobalVariableEdit.R1Name;
            ReferenceWaveformTwoName = GlobalVariableEdit.R2Name;
            ReferenceWaveformThreeName = GlobalVariableEdit.R3Name;
            ReferenceWaveformFourName = GlobalVariableEdit.R4Name;
            ReferenceWaveformFiveName = GlobalVariableEdit.R5Name;
            ReferenceWaveformSixName = GlobalVariableEdit.R6Name;
            ReferenceWaveformSevenName = GlobalVariableEdit.R7Name;
            ReferenceWaveformEightName = GlobalVariableEdit.R8Name;
        }


        #endregion


        #region 最近使用文件

        /// <summary>
        /// 要显示的最近使用文件日志集合
        /// </summary>
        private ObservableCollection<UsedFileLog> _ShowUsedFileLogList = new ObservableCollection<UsedFileLog>();

        /// <summary>
        /// 要显示的最近使用文件日志集合
        /// </summary>
        public ObservableCollection<UsedFileLog> ShowUsedFileLogList
        {
            get { return _ShowUsedFileLogList; }
            set
            {
                _ShowUsedFileLogList = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 临时要显示的最近使用文件日志集合
        /// </summary>
        private ObservableCollection<UsedFileLog> _TempShowUsedFileLogList;

        /// <summary>
        /// 临时要显示的最近使用文件日志集合
        /// </summary>
        public ObservableCollection<UsedFileLog> TempShowUsedFileLogList
        {
            get { return _TempShowUsedFileLogList; }
            set { 
                _TempShowUsedFileLogList = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 是否使用查询-要显示的最近使用文件日志集合
        /// </summary>
        public bool IsQueryShowUsedFileLog { get; set; } = false;

        /// <summary>
        /// 更新最近使用的文件信息
        /// </summary>
        private void UpdateShowUsedFileLogList()
        {
            ShowUsedFileLogList = GetList(GlobalVariableEdit.UsedFileLogList);
            TempShowUsedFileLogList = GetList(ShowUsedFileLogList);


            if (IsQueryShowUsedFileLog)
            {
                // 使用文件记录根据条件查询
                FileTypeQueryFun();
            }
            

            RaisePropertyChanged("TempShowUsedFileLogList");
        }

        /// <summary>
        /// 获取使用过文件日志
        /// </summary>
        /// <returns></returns>
        private ObservableCollection<UsedFileLog> GetList(ObservableCollection<UsedFileLog> list)
        {
            ObservableCollection<UsedFileLog> usedFileLogList = new ObservableCollection<UsedFileLog>();

            for (int i = 0; i < list.Count; i++)
            {
                usedFileLogList.Add(new UsedFileLog()
                {
                    Fid = list[i].Fid,
                    FileName = list[i].FileName,
                    FileType = list[i].FileType,
                    Operation = list[i].Operation,
                    Time = list[i].Time,
                    Uid = list[i].Uid,
                });
            }

            return usedFileLogList;
        }

        #endregion


        #region 操作日志

        /// <summary>
        /// 操作日志集合
        /// </summary>
        private ObservableCollection<AllUsedLog> _UsedLogList;

        /// <summary>
        /// 操作日志集合
        /// </summary>
        public ObservableCollection<AllUsedLog> UsedLogList
        {
            get { return _UsedLogList; }
            set
            {
                _UsedLogList = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 临时操作日志集合
        /// </summary>
        private ObservableCollection<AllUsedLog> _TempUsedLogList;

        /// <summary>
        /// 临时操作日志集合
        /// </summary>
        public ObservableCollection<AllUsedLog> TempUsedLogList
        {
            get { return _TempUsedLogList; }
            set
            {
                _TempUsedLogList = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 索引集合
        /// </summary>
        private List<int> _IndexList = new List<int>();

        /// <summary>
        /// 索引集合
        /// </summary>
        public List<int> IndexList
        {
            get { return _IndexList; }
            set { _IndexList = value; }
        }

        /// <summary>
        /// 是否查询-操作日志集合
        /// </summary>
        public bool IsQueryUsedLog { get; set; } = false;

        /// <summary>
        /// 更新最近使用的文件信息
        /// </summary>
        private void UpdateUsedLogList()
        {
            UsedLogList = GetLogList(GlobalVariableEdit.UsedLogList);
            TempUsedLogList = GetLogList(UsedLogList);

            if (IsQueryUsedLog)
            {
                // 操作日志根据条件查询
                WorkLogQueryFun();
            }

            RaisePropertyChanged("TempUsedLogList");
        }

        /// <summary>
        /// 获取使用过文件日志
        /// </summary>
        /// <returns></returns>
        private ObservableCollection<AllUsedLog> GetLogList(ObservableCollection<AllUsedLog> list)
        {
            ObservableCollection<AllUsedLog> usedLogList = new ObservableCollection<AllUsedLog>();

            for (int i = 0; i < list.Count; i++)
            {
                usedLogList.Add(new AllUsedLog()
                {
                    Aid = list[i].Aid,
                    Uid = list[i].Uid,
                    Time = list[i].Time,
                    OperateDescription = list[i].OperateDescription,
                });
            }

            return usedLogList;
        }

        #endregion


        #region 选择要显示的列
        /// <summary>
        /// 选择要显示的列
        /// </summary>
        public DelegateCommand SelectTheColumnsToDisplayCmm { get; set; }

        /// <summary>
        /// 选择要显示的列
        /// </summary>
        private async void SelectTheColumnsToDisplayFun()
        {
            DialogParameters paras = new DialogParameters();

            List<bool> list = ColumnsStatus(AidVisibility, UidVisibility, TimeVisibility, OperateVisibility);

            paras.Add("Title", LangugeConvertor.GetValue("CheckTheShowColumnspage"));
            paras.Add("list", list);

            // 打开对话框
            var result = await DialogHostService.ShowDialog("SelectTheColumnsToDisplayUC", paras);

            if (result.Result == ButtonResult.Yes)
            {
                // 索引号
                if (result.Parameters.GetValue<bool>("IndexChecked"))
                {
                    AidVisibility = Visibility.Visible;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(0);
                }
                else
                {
                    AidVisibility = Visibility.Collapsed;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(1);
                }

                // 用户
                if (result.Parameters.GetValue<bool>("UserChecked"))
                {
                    UidVisibility = Visibility.Visible;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(2);
                }
                else
                {
                    UidVisibility = Visibility.Collapsed;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(3);
                }

                // 时间
                if (result.Parameters.GetValue<bool>("TimeChecked"))
                {
                    TimeVisibility = Visibility.Visible;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(4);
                }
                else
                {
                    TimeVisibility = Visibility.Collapsed;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(5);
                }

                // 操作描述
                if (result.Parameters.GetValue<bool>("OperateDescriptionChecked"))
                {
                    OperateVisibility = Visibility.Visible;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(6);
                }
                else
                {
                    OperateVisibility = Visibility.Collapsed;
                    Aggregator.GetEvent<MsgFormSelectTheColumnsToDisplay>().Publish(7);
                }
            }
        }

        /// <summary>
        /// 列的状态
        /// </summary>
        private List<bool> ColumnsStatus(Visibility AidVisibility, Visibility UidVisibility, Visibility TimeVisibility, Visibility OperateVisibility)
        {
            var newBoolList = new List<bool>();

            // 索引号
            if (AidVisibility == Visibility.Visible)
            {
                newBoolList.Add(true);
            }
            else
            {
                newBoolList.Add(false);
            }

            // 用户
            if (UidVisibility == Visibility.Visible)
            {
                newBoolList.Add(true);
            }
            else
            {
                newBoolList.Add(false);
            }

            // 时间
            if (TimeVisibility == Visibility.Visible)
            {
                newBoolList.Add(true);
            }
            else
            {
                newBoolList.Add(false);
            }

            // 操作描述
            if (OperateVisibility == Visibility.Visible)
            {
                newBoolList.Add(true);
            }
            else
            {
                newBoolList.Add(false);
            }

            return newBoolList;
        }


        /// <summary>
        /// 索引号是否显示
        /// </summary>
        private Visibility _AidVisibility = Visibility.Visible;

        /// <summary>
        /// 索引号是否显示
        /// </summary>
        public Visibility AidVisibility
        {
            get { return _AidVisibility; }
            set
            {
                _AidVisibility = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 用户id是否显示
        /// </summary>
        private Visibility _UidVisibility = Visibility.Visible;

        /// <summary>
        /// 用户id是否显示
        /// </summary>
        public Visibility UidVisibility
        {
            get { return _UidVisibility; }
            set
            {
                _UidVisibility = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 时间是否显示
        /// </summary>
        private Visibility _TimeVisibility = Visibility.Visible;

        /// <summary>
        /// 时间是否显示
        /// </summary>
        public Visibility TimeVisibility
        {
            get { return _TimeVisibility; }
            set
            {
                _TimeVisibility = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 操作描述是否显示
        /// </summary>
        private Visibility _OperateVisibility = Visibility.Visible;

        /// <summary>
        /// 操作描述是否显示
        /// </summary>
        public Visibility OperateVisibility
        {
            get { return _OperateVisibility; }
            set
            {
                _OperateVisibility = value;
                RaisePropertyChanged();
            }
        }


        #endregion


        #region 使用文件记录-条件查询

        /// <summary>
        /// 使用文件记录起始日期
        /// </summary>
        private DateTime _FileTypeStartDate = DateTime.Now;

        /// <summary>
        /// 使用文件记录起始日期
        /// </summary>
        public DateTime FileTypeStartDate
        {
            get { return _FileTypeStartDate; }
            set { 
                _FileTypeStartDate = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 使用文件记录起始时间
        /// </summary>
        private string _FileTypeStartTime = "00:00:00";

        /// <summary>
        /// 使用文件记录起始时间
        /// </summary>
        public string FileTypeStartTime
        {
            get { return _FileTypeStartTime; }
            set { 
                _FileTypeStartTime = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 使用文件记录截止日期
        /// </summary>
        private DateTime _FileTypeDeadlineDate = DateTime.Now;

        /// <summary>
        /// 使用文件记录截止日期
        /// </summary>
        public DateTime FileTypeDeadlineDate
        {
            get { return _FileTypeDeadlineDate; }
            set { 
                _FileTypeDeadlineDate = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 使用文件记录截止时间
        /// </summary>
        private string _FileTypeDeadlineTime = "23:59:59";

        /// <summary>
        /// 使用文件记录截止时间
        /// </summary>
        public string FileTypeDeadlineTime
        {
            get { return _FileTypeDeadlineTime; }
            set { 
                _FileTypeDeadlineTime = value;
                RaisePropertyChanged();
            }
        }


        private DateTime _FileTypeStartDateTime;

        public DateTime FileTypeStartDateTime
        {
            get { return _FileTypeStartDateTime; }
            set { 
                _FileTypeStartDateTime = value;
                RaisePropertyChanged();
            }
        }


        private DateTime _FileTypeDeadlineDateTime;

        public DateTime FileTypeDeadlineDateTime
        {
            get { return _FileTypeDeadlineDateTime; }
            set { 
                _FileTypeDeadlineDateTime = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 文件类型下标
        /// </summary>
        public int FileTypeIndex { get; set; } = 5;

        /// <summary>
        /// 文件类型选择
        /// </summary>
        public DelegateCommand<int?> FileTypeSelectionChangedCmm { get; set; }

        /// <summary>
        /// 文件类型选择
        /// </summary>
        /// <param name="index"></param>
        private void FileTypeSelectionChangedFun(int? index)
        {
            FileTypeIndex = (int)index;

            IsQueryShowUsedFileLog = true;
        }

        /// <summary>
        /// 使用文件记录根据条件查询
        /// </summary>
        public DelegateCommand FileTypeQueryCmm { get; set; }

        /// <summary>
        /// 使用文件记录根据条件查询
        /// </summary>
        private void FileTypeQueryFun()
        {
            // 选择全部
            if (FileTypeIndex == 5)
            {
                All();

                return;
            }


            Condition();

        }


        /// <summary>
        ///  全部查询
        /// </summary>
        private void All()
        {
            string fileTypeStartDateTime = string.Concat(FileTypeStartDate.ToString().Split(" ")[0], " ", FileTypeStartTime);
            FileTypeStartDateTime = DateTime.Parse(fileTypeStartDateTime);
            FileTypeStartDate = FileTypeStartDateTime;
            FileTypeStartTime = FileTypeStartDateTime.TimeOfDay.ToString();

            string fileTypeDeadlineDateTime = string.Concat(FileTypeDeadlineDate.ToString().Split(" ")[0], " ", FileTypeDeadlineTime);
            FileTypeDeadlineDateTime = DateTime.Parse(fileTypeDeadlineDateTime);
            FileTypeDeadlineDate = FileTypeDeadlineDateTime;
            FileTypeDeadlineTime = FileTypeDeadlineDateTime.TimeOfDay.ToString();


            TempShowUsedFileLogList = new ObservableCollection<UsedFileLog>(ShowUsedFileLogList.Where(u => u.Time >= FileTypeStartDateTime && u.Time <= FileTypeDeadlineDateTime));
            RaisePropertyChanged("TempShowUsedFileLogList");
        }

        /// <summary>
        /// 文件类型查询
        /// </summary>
        private void Condition()
        {
            string fileTypeStartDateTime = string.Concat(FileTypeStartDate.ToString().Split(" ")[0], " ", FileTypeStartTime);
            FileTypeStartDateTime = DateTime.Parse(fileTypeStartDateTime);
            FileTypeStartDate = FileTypeStartDateTime;
            FileTypeStartTime = FileTypeStartDateTime.TimeOfDay.ToString();

            string fileTypeDeadlineDateTime = string.Concat(FileTypeDeadlineDate.ToString().Split(" ")[0], " ", FileTypeDeadlineTime);
            FileTypeDeadlineDateTime = DateTime.Parse(fileTypeDeadlineDateTime);
            FileTypeDeadlineDate = FileTypeDeadlineDateTime;
            FileTypeDeadlineTime = FileTypeDeadlineDateTime.TimeOfDay.ToString();


            TempShowUsedFileLogList = new ObservableCollection<UsedFileLog>(ShowUsedFileLogList.Where(u => u.Time >= FileTypeStartDateTime 
            && u.Time <= FileTypeDeadlineDateTime && (int)(u.FileType) == FileTypeIndex ));
            RaisePropertyChanged("TempShowUsedFileLogList");
        }



        #endregion


        #region 操作日志-条件查询

        /// <summary>
        /// 操作日志起始日期
        /// </summary>
        private DateTime _WorkLogStartDate = DateTime.Now;

        /// <summary>
        /// 操作日志起始日期
        /// </summary>
        public DateTime WorkLogStartDate
        {
            get { return _WorkLogStartDate; }
            set { 
                _WorkLogStartDate = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 操作日志起始时间
        /// </summary>
        private string _WorkLogStartTime = "00:00:00";

        /// <summary>
        /// 操作日志起始时间
        /// </summary>
        public string WorkLogStartTime
        {
            get { return _WorkLogStartTime; }
            set { 
                _WorkLogStartTime = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 操作日志截止日期
        /// </summary>
        private DateTime _WorkLogDeadlineDate = DateTime.Now;

        /// <summary>
        /// 操作日志截止日期
        /// </summary>
        public DateTime WorkLogDeadlineDate
        {
            get { return _WorkLogDeadlineDate; }
            set { 
                _WorkLogDeadlineDate = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 操作日志截止时间
        /// </summary>
        private string _WorkLogDeadlineTime = "23:59:59";

        /// <summary>
        /// 操作日志截止时间
        /// </summary>
        public string WorkLogDeadlineTime
        {
            get { return _WorkLogDeadlineTime; }
            set { 
                _WorkLogDeadlineTime = value;
                RaisePropertyChanged();
            }
        }



        private DateTime _WorkLogStartDateTime;

        public DateTime WorkLogStartDateTime
        {
            get { return _WorkLogStartDateTime; }
            set { 
                _WorkLogStartDateTime = value;
                RaisePropertyChanged();
            }
        }

        private DateTime _WorkLogDeadlineDateTime;

        public DateTime WorkLogDeadlineDateTime
        {
            get { return _WorkLogDeadlineDateTime; }
            set { 
                _WorkLogDeadlineDateTime = value;
                RaisePropertyChanged();
            }
        }



        /// <summary>
        /// 操作日志根据条件查询
        /// </summary>
        public DelegateCommand WorkLogQueryCmm { get; set; }


        /// <summary>
        /// 操作日志根据条件查询
        /// </summary>
        private void WorkLogQueryFun()
        {

            string workLogStartDateTime = string.Concat(WorkLogStartDate.ToString().Split(" ")[0], " ", WorkLogStartTime);
            WorkLogStartDateTime = DateTime.Parse(workLogStartDateTime);
            WorkLogStartDate = WorkLogStartDateTime;
            WorkLogStartTime = WorkLogStartDateTime.TimeOfDay.ToString();

            string workLogDeadlineDateTime = string.Concat(WorkLogDeadlineDate.ToString().Split(" ")[0], " ", WorkLogDeadlineTime);
            WorkLogDeadlineDateTime = DateTime.Parse(workLogDeadlineDateTime);
            WorkLogDeadlineDate = WorkLogDeadlineDateTime;
            WorkLogDeadlineTime = WorkLogDeadlineDateTime.TimeOfDay.ToString();


            TempUsedLogList = new ObservableCollection<AllUsedLog>(UsedLogList.Where(u => u.Time >= WorkLogStartDateTime  && u.Time <= WorkLogDeadlineDateTime));
            RaisePropertyChanged("TempUsedLogList");

            IsQueryUsedLog = true;
        }

        #endregion
    }
}
